package com.pine.dbant.common.context;


import com.pine.sunflower.core.Context;
import com.pine.sunflower.core.plugin.Configuration;
import lombok.Getter;
import lombok.Setter;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * 应用上下文
 *
 * @author xiaoyuan
 * @create 2022/6/2 11:54
 **/
@Getter
@Setter
public class AppContext extends Context {

    /**
     * 该节点是否可用 true表示运行中  false表示停止了
     */
    private static  AtomicBoolean available = new AtomicBoolean(false);

    private static Configuration configuration = Configuration.from("{}");

    /**
     * 应用停止了
     */
    public static void stop() {
        available.set(false);
    }

    /**
     * 启动成功
     */
    public static void starter() {
        available.set(true);
    }

    /**
     * 是否运行
     *
     * @return
     */
    public static  boolean isRunning() {
        return available.get();
    }

    /**
     * 引用是否停止
     *
     * @return
     */
    public static boolean isStop() {
        return !available.get();
    }

    public static Configuration getConfiguration(){
        return configuration;
    }

}
